package com.myhexin.demo.ruleengine;

import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;

public class QLExpressMacroExample {
    public static void main(String[] args) {
        try {
            ExpressRunner runner = new ExpressRunner();
            DefaultContext<String, Object> context = new DefaultContext<>();

            // 定义宏
            runner.addMacro("计算平均成绩", "(语文+数学+英语)/3.0");
            runner.addMacro("是否优秀", "计算平均成绩>90");

            // 设置变量值
            context.put("语文", 88);
            context.put("数学", 99);
            context.put("英语", 95);

            // 执行表达式并打印结果
            Object result = runner.execute("是否优秀", context, null, false, false);
            System.out.println("Result: " + result);
            Object result2 = runner.execute("计算平均成绩", context, null, false, false);
            System.out.println("Result2: " + result2);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
